import { CyclePeriod } from '../../domain/CyclePeriod'
import { DayOfWeek } from '../../domain/DayOfWeek'
import Task from './Task'
import NamedString from "../../core/NamedString";
import dayjs, { Dayjs } from "dayjs";
import { Consts } from "@/core/Consts";

export default class Schedule extends NamedString {
  public startDate: string = dayjs().format(Consts.dateFormat);
  public endDate?: string;
  public forever?: boolean;
  public cyclePeriod: CyclePeriod = CyclePeriod.EVERYDAY;
  public dayOfWeeks: DayOfWeek[] = [];
  public tasks: Task[] = [];
  public disable: boolean = false;
  public descr?: string;

  public get startDate_ (): Dayjs {
    return dayjs(this.startDate);
  }

  public set startDate_ (value: Dayjs) {
    this.startDate = value.format(Consts.dateFormat);
  }

  public get endDate_ (): Dayjs | undefined {
    // return this.endDate && dayjs(this.endDate)
    return this.endDate ? dayjs(this.endDate) : undefined;
  }

  public set endDate_ (value: Dayjs | undefined) {
    this.endDate = value ? value.format(Consts.dateFormat) : undefined;
  }

  public get forever_ (): boolean | undefined {
    return this.forever;
  }

  public set forever_ (value: boolean) {
    if (value) {  
      this.endDate_ = undefined
    }
    this.forever = value
  }

  public get cyclePeriod_ (): CyclePeriod {
    return this.cyclePeriod;
  }

  public set cyclePeriod_ (value: CyclePeriod) {
    if (value !== 'CUSTOM') {
      this.dayOfWeeks = []
    }
    this.cyclePeriod = value
  }

}
